<?php
class CodeSpace_Oauth_Server_Consumer_Authentication_Database
{
    private $_databaseTableName = null;
    private $_databaseTableColumnName = null;
    
    public function __construct($tableName = null, $columnName = null)
    {
        if(! is_null($tableName))
        {
            $this->_databaseTableName = $tableName;
        }
        
        if(! is_null($columnName))
        {
            $this->_databaseTableColumnName;
        }
    }
    
    public function setDatabaseTableName($name)
    {
        $this->_databaseTableName = $name;
    }
    
    public function getDatabaseTableName()
    {
        return $this->_databaseTableName;
    }
    
    public function setDatabaseTableColumnName($columnName)
    {
        $this->_databaseTableColumnName = $columnName;
    }
    
    public function getDatabaseTableColumnName()
    {
        return $this->_databaseTableColumnName;
    }
     
    public function authenticate($key)
    {
        $table = new $this->_databaseTableName;
        $q = $table->select()->where($this->_databaseTableColumnName . ' = ?', $key);
        $resultSet = $table->fetchAll($q);

        if($resultSet->count() == 1)
        {
            $row = $resultSet->current();

            $consumer = array();
            $consumer[$key] = array(
                'secret'	=>    $row->con_secret
            );
            return $consumer;
        }
        
        return false;
    }
}
?>